package com.example.creatation.prototype;

/**
 * Cloneable 代表当前对象是可以克隆的
 */
public class User implements Cloneable{
    private String username;
    private Integer age;

    public User() {
        System.out.println("create User");
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public User clone() {
            User clone = new User();
            clone.setAge(age);
            clone.setUsername(username);
            // TODO: copy mutable state here, so the clone can't change the internals of the original
            return clone;
    }
}
